130
class Solution {
    boolean[][] flag;
    int x, y;
    public void solve(char[][] board) {
        x = board.length;
        y = board[0].length;
        flag = new boolean[x][y];
        char[][] tmp = new char[x][y];
        for (int i = 0; i  x; i++) {
            for (int j = 0; j  y; j++) {
                if (!flag[i][j] && board[i][j] == 'O') {
                    flag[i][j] = true;
                    boolean[] ret = new boolean[1];
                    for (int m = 0; m  x; m++) {
                        tmp[m] = Arrays.copyOf(board[m], y);
                    }
                    fun(tmp, i, j, ret);
                    if (!ret[0]) {
                        for (int m = 0; m  x; m++) {
                            board[m] = Arrays.copyOf(tmp[m], y);
                        }
                    }
                }
            }
        }
        
    }
    public void fun(char[][] tmp, int i, int j, boolean[] ret) {
        if (i == x-1  i == 0  j == 0  j == y-1) {
            ret[0] = true;
        }
        char a = 'O';
        tmp[i][j] = 'X';
        flag[i][j] = true;
        i++;
        if (i  x && tmp[i][j] == a) {
            fun(tmp, i, j, ret);
        }
        i -= 2;
        if (i = 0 && tmp[i][j] == a) {
            fun(tmp, i, j, ret);
        }
        i++;
        j++;
        if (j  y && tmp[i][j] == a) {
            fun(tmp, i, j, ret);
        }
        j -= 2;
        if (j = 0 && tmp[i][j] == a) {
            fun(tmp, i, j, ret);
        }
    }
}